/*      */ package com.zimbra.qa.unittest.prov.ldap;
/*      */ 
/*      */ import com.google.common.collect.Sets;
/*      */ import com.zimbra.common.account.Key.AccountBy;
/*      */ import com.zimbra.common.account.Key.DistributionListBy;
/*      */ import com.zimbra.common.account.Key.DomainBy;
/*      */ import com.zimbra.common.account.Key.XMPPComponentBy;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.util.ZimbraLog;
/*      */ import com.zimbra.cs.account.Account;
/*      */ import com.zimbra.cs.account.Alias;
/*      */ import com.zimbra.cs.account.DataSource;
/*      */ import com.zimbra.cs.account.DistributionList;
/*      */ import com.zimbra.cs.account.Domain;
/*      */ import com.zimbra.cs.account.DynamicGroup;
/*      */ import com.zimbra.cs.account.Group;
/*      */ import com.zimbra.cs.account.IDNUtil;
/*      */ import com.zimbra.cs.account.Identity;
/*      */ import com.zimbra.cs.account.MailTarget;
/*      */ import com.zimbra.cs.account.NamedEntry;
/*      */ import com.zimbra.cs.account.Provisioning;
/*      */ import com.zimbra.cs.account.SearchDirectoryOptions;
/*      */ import com.zimbra.cs.account.SearchDirectoryOptions.ObjectType;
/*      */ import com.zimbra.cs.account.Server;
/*      */ import com.zimbra.cs.account.Signature;
/*      */ import com.zimbra.cs.account.XMPPComponent;
/*      */ import com.zimbra.cs.account.ldap.LdapProv;
/*      */ import com.zimbra.cs.account.ldap.LdapProvisioning;
/*      */ import com.zimbra.cs.ldap.LdapUtil;
/*      */ import com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId;
/*      */ import com.zimbra.qa.unittest.prov.Names.IDNName;
/*      */ import com.zimbra.qa.unittest.prov.Verify;
/*      */ import com.zimbra.soap.admin.type.CacheEntryType;
/*      */ import com.zimbra.soap.admin.type.DataSourceType;
/*      */ import java.io.PrintStream;
/*      */ import java.util.ArrayList;
/*      */ import java.util.Arrays;
/*      */ import java.util.Collection;
/*      */ import java.util.Collections;
/*      */ import java.util.HashMap;
/*      */ import java.util.HashSet;
/*      */ import java.util.Iterator;
/*      */ import java.util.List;
/*      */ import java.util.Map;
/*      */ import java.util.Map.Entry;
/*      */ import java.util.Set;
/*      */ import java.util.TreeMap;
/*      */ import junit.framework.AssertionFailedError;
/*      */ import org.junit.AfterClass;
/*      */ import org.junit.Assert;
/*      */ import org.junit.BeforeClass;
/*      */ import org.junit.Test;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class TestLdapProvRenameDomain
/*      */   extends LdapTest
/*      */ {
/*      */   private static LdapProv ldapProv;
/*      */   private static Provisioning prov;
/*      */   private static String TEST_ID;
/*   69 */   private static String PASSWORD = "test123";
/*      */   
/*   71 */   private static int NUM_ACCOUNTS = 3;
/*   72 */   private static int NUM_CAS = 3;
/*   73 */   private static int NUM_DLS_NESTED = 2;
/*   74 */   private static int NUM_DLS_TOP = 2;
/*   75 */   private static int NUM_DYNAMIC_GROUPS = 2;
/*   76 */   private static int NUM_DOMAINS = 3;
/*   77 */   private static int NUM_SUB_DOMAINS = 2;
/*   78 */   private static int NUM_XMPPCOMPONENTS = 3;
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*   89 */   private static int NUM_SIGNATURES = 2;
/*   90 */   private static int NUM_IDENTITIES = 2;
/*   91 */   private static int NUM_DATASOURCES = 2;
/*      */   
/*   93 */   private static String NAME_LEAF_OLD_DOMAIN = "olddomain";
/*   94 */   private static String NAME_LEAF_NEW_DOMAIN = "newdomain";
/*   95 */   private static String UNICODESTR = "中文";
/*      */   
/*      */ 
/*   98 */   private static String NAMEPREFIX_ACCOUNT = "acct-";
/*   99 */   private static String NAMEPREFIX_ALIAS = "alias-";
/*  100 */   private static String NAMEPREFIX_DATASOURCE = "datasource-";
/*  101 */   private static String NAMEPREFIX_DL_NESTED = "nesteddl-";
/*  102 */   private static String NAMEPREFIX_DL_TOP = "topdl-";
/*  103 */   private static String NAMEPREFIX_DYNAMIC_GROUP = "dynamicgroup-";
/*  104 */   private static String NAMEPREFIX_IDENTITY = "identity-";
/*  105 */   private static String NAMEPREFIX_OTHERDOMAIN = "otherdomain-";
/*  106 */   private static String NAMEPREFIX_SIGNATURE = "signature-";
/*  107 */   private static String NAMEPREFIX_SUB_DOMAIN = "subdomian-";
/*      */   
/*      */ 
/*  110 */   private static int OLD_DOMAIN = 0;
/*  111 */   private static int NEW_DOMAIN = -1;
/*      */   
/*      */   private static final int OBJ_ACCT = 1;
/*      */   
/*      */   private static final int OBJ_DL_NESTED = 2;
/*      */   
/*      */   private static final int OBJ_DL_TOP = 4;
/*      */   
/*      */   private static final int OBJ_DYNAMIC_GROUP = 8;
/*      */   
/*  121 */   private static final Set<String> sAttrsToVerify = new HashSet();
/*      */   
/*  123 */   static { sAttrsToVerify.add("zimbraMailCanonicalAddress");
/*  124 */     sAttrsToVerify.add("zimbraMailForwardingAddress");
/*  125 */     sAttrsToVerify.add("zimbraMailCatchAllAddress");
/*  126 */     sAttrsToVerify.add("zimbraMailCatchAllCanonicalAddress");
/*  127 */     sAttrsToVerify.add("zimbraMailCatchAllForwardingAddress");
/*  128 */     sAttrsToVerify.add("zimbraPrefAllowAddressForDelegatedSender");
/*      */   }
/*      */   
/*      */   int NUM_OBJS(int objType) throws Exception {
/*  132 */     switch (objType) {
/*      */     case 1: 
/*  134 */       return NUM_ACCOUNTS;
/*      */     case 2: 
/*  136 */       return NUM_DLS_NESTED;
/*      */     case 4: 
/*  138 */       return NUM_DLS_TOP;
/*      */     case 8: 
/*  140 */       return NUM_DYNAMIC_GROUPS;
/*      */     }
/*  142 */     throw new Exception();
/*      */   }
/*      */   
/*      */   String OBJ_NAME(int objType, int index, int domainIdx) throws Exception {
/*  146 */     switch (objType) {
/*      */     case 1: 
/*  148 */       return ACCOUNT_NAME(index, domainIdx);
/*      */     case 2: 
/*  150 */       return NESTED_DL_NAME(index, domainIdx);
/*      */     case 4: 
/*  152 */       return TOP_DL_NAME(index, domainIdx);
/*      */     case 8: 
/*  154 */       return DYNAMIC_GROUP_NAME(index, domainIdx);
/*      */     }
/*  156 */     throw new Exception();
/*      */   }
/*      */   
/*      */   String GET_ALIAS_NAME(int objType, int targetIdx, int targetDomainIdx, int aliasDomainIdx) throws Exception {
/*  160 */     switch (objType) {
/*      */     case 1: 
/*  162 */       return ACCOUNT_ALIAS_NAME(targetIdx, targetDomainIdx, aliasDomainIdx);
/*      */     case 2: 
/*  164 */       return NESTED_DL_ALIAS_NAME(targetIdx, targetDomainIdx, aliasDomainIdx);
/*      */     case 4: 
/*  166 */       return TOP_DL_ALIAS_NAME(targetIdx, targetDomainIdx, aliasDomainIdx);
/*      */     case 8: 
/*  168 */       return DYNAMIC_GROUP_ALIAS_NAME(targetIdx, targetDomainIdx, aliasDomainIdx);
/*      */     }
/*  170 */     throw new Exception();
/*      */   }
/*      */   
/*      */   private void setLdapProv() {
/*  174 */     prov = ldapProv;
/*      */   }
/*      */   
/*      */   @BeforeClass
/*      */   public static void init() throws Exception
/*      */   {
/*  180 */     ZimbraLog.toolSetupLog4j("INFO", "/opt/zimbra/conf/log4j.properties");
/*      */     
/*  182 */     TEST_ID = genTestId();
/*      */     
/*  184 */     System.out.println("\nTest " + TEST_ID + "\n");
/*      */     
/*  186 */     Provisioning prov = Provisioning.getInstance();
/*  187 */     Assert.assertTrue(prov instanceof LdapProv);
/*  188 */     ldapProv = (LdapProv)prov;
/*      */   }
/*      */   
/*      */   @AfterClass
/*      */   public static void cleanup() throws Exception {
/*  193 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*      */   }
/*      */   
/*      */   private void prepareDomain() throws Exception
/*      */   {
/*  198 */     setLdapProv();
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  227 */     for (int i = 0; i < NUM_DOMAINS; i++) {
/*  228 */       createDomain(DOMAIN_NAME(i));
/*      */     }
/*      */     
/*  231 */     for (int i = 0; i < NUM_SUB_DOMAINS; i++) {
/*  232 */       createDomain(SUB_DOMAIN_NAME(i, OLD_DOMAIN));
/*      */     }
/*      */     
/*  235 */     for (int i = 0; i < NUM_DOMAINS; i++) {
/*  236 */       populateDomain(i);
/*      */     }
/*  238 */     for (int i = 0; i < NUM_DOMAINS; i++) {
/*  239 */       setupDLs(i);
/*      */     }
/*      */     
/*  242 */     Domain oldDomain = prov.get(Key.DomainBy.name, DOMAIN_NAME(OLD_DOMAIN));
/*  243 */     for (int i = 0; i < NUM_XMPPCOMPONENTS; i++) {
/*  244 */       createXMPPComponent(i, oldDomain);
/*      */     }
/*      */   }
/*      */   
/*      */   private int DOMAIN_INDEX_AFTER_RENAME(int domainIdx) {
/*  249 */     if (domainIdx == OLD_DOMAIN) {
/*  250 */       return NEW_DOMAIN;
/*      */     }
/*  252 */     return domainIdx;
/*      */   }
/*      */   
/*      */   private String DOMAIN_NAME(String leafDomainName) {
/*  256 */     return leafDomainName + "." + UNICODESTR + "." + baseDomainName();
/*      */   }
/*      */   
/*      */   private String SUB_DOMAIN_NAME(int index, int parentDomain) {
/*  260 */     int idx = index + 1;
/*  261 */     String parentDomainName = DOMAIN_NAME(parentDomain);
/*  262 */     return NAMEPREFIX_SUB_DOMAIN + idx + "." + parentDomainName;
/*      */   }
/*      */   
/*      */   private String LEAF_DOMAIN_NAME(int index) {
/*  266 */     if (index == OLD_DOMAIN)
/*  267 */       return NAME_LEAF_OLD_DOMAIN;
/*  268 */     if (index == NEW_DOMAIN) {
/*  269 */       return NAME_LEAF_NEW_DOMAIN;
/*      */     }
/*  271 */     return NAMEPREFIX_OTHERDOMAIN + index;
/*      */   }
/*      */   
/*      */   private String DOMAIN_NAME(int index) {
/*  275 */     return DOMAIN_NAME(LEAF_DOMAIN_NAME(index));
/*      */   }
/*      */   
/*      */   private String XMPPCOMPONENT_NAME(int index, String domainName) {
/*  279 */     return "xmppcomponent-" + index + "." + domainName;
/*      */   }
/*      */   
/*      */   private String ACCOUNT_LOCAL(int index)
/*      */   {
/*  284 */     return NAMEPREFIX_ACCOUNT + String.valueOf(index + 1);
/*      */   }
/*      */   
/*      */   private String ACCOUNT_NAME(int index, int domainIdx) {
/*  288 */     return ACCOUNT_LOCAL(index) + "@" + DOMAIN_NAME(domainIdx);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private Set<String> ACCOUNT_NAMES(int index, int domainIdx, boolean afterRename)
/*      */   {
/*  297 */     int dIdx = afterRename ? DOMAIN_INDEX_AFTER_RENAME(domainIdx) : domainIdx;
/*  298 */     Set<String> names = new HashSet();
/*  299 */     String name = ACCOUNT_NAME(index, dIdx);
/*  300 */     names.add(name);
/*  301 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/*  302 */       String aliasName = ACCOUNT_ALIAS_NAME(index, d, afterRename ? DOMAIN_INDEX_AFTER_RENAME(d) : d);
/*  303 */       names.add(aliasName);
/*      */     }
/*  305 */     return names;
/*      */   }
/*      */   
/*      */   private String ACCOUNT_ALIAS_NAME(int targetIdx, int targetDomainIdx, int aliasDomainIdx) {
/*  309 */     return NAMEPREFIX_ALIAS + ACCOUNT_LOCAL(targetIdx) + "-" + LEAF_DOMAIN_NAME(targetDomainIdx) + "@" + DOMAIN_NAME(aliasDomainIdx);
/*      */   }
/*      */   
/*      */   private String TOP_DL_LOCAL(int index)
/*      */   {
/*  314 */     return NAMEPREFIX_DL_TOP + String.valueOf(index + 1);
/*      */   }
/*      */   
/*      */   private String DYNAMIC_GROUP_LOCAL(int index)
/*      */   {
/*  319 */     return NAMEPREFIX_DYNAMIC_GROUP + String.valueOf(index + 1);
/*      */   }
/*      */   
/*      */   private String TOP_DL_NAME(int index, int domainIdx) {
/*  323 */     return TOP_DL_LOCAL(index) + "@" + DOMAIN_NAME(domainIdx);
/*      */   }
/*      */   
/*      */   private String DYNAMIC_GROUP_NAME(int index, int domainIdx) {
/*  327 */     return DYNAMIC_GROUP_LOCAL(index) + "@" + DOMAIN_NAME(domainIdx);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private Set<String> TOP_DL_NAMES(int index, int domainIdx, boolean afterRename)
/*      */   {
/*  334 */     int dIdx = afterRename ? DOMAIN_INDEX_AFTER_RENAME(domainIdx) : domainIdx;
/*  335 */     Set<String> names = new HashSet();
/*  336 */     String name = TOP_DL_NAME(index, dIdx);
/*  337 */     names.add(name);
/*  338 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/*  339 */       String aliasName = TOP_DL_ALIAS_NAME(index, d, afterRename ? DOMAIN_INDEX_AFTER_RENAME(d) : d);
/*  340 */       names.add(aliasName);
/*      */     }
/*  342 */     return names;
/*      */   }
/*      */   
/*      */   private String TOP_DL_ALIAS_NAME(int targetIdx, int targetDomainIdx, int aliasDomainIdx) {
/*  346 */     return NAMEPREFIX_ALIAS + TOP_DL_LOCAL(targetIdx) + "-" + LEAF_DOMAIN_NAME(targetDomainIdx) + "@" + DOMAIN_NAME(aliasDomainIdx);
/*      */   }
/*      */   
/*      */   private String DYNAMIC_GROUP_ALIAS_NAME(int targetIdx, int targetDomainIdx, int aliasDomainIdx) {
/*  350 */     return NAMEPREFIX_ALIAS + DYNAMIC_GROUP_LOCAL(targetIdx) + "-" + LEAF_DOMAIN_NAME(targetDomainIdx) + "@" + DOMAIN_NAME(aliasDomainIdx);
/*      */   }
/*      */   
/*      */   private String NESTED_DL_LOCAL(int index)
/*      */   {
/*  355 */     return NAMEPREFIX_DL_NESTED + String.valueOf(index + 1);
/*      */   }
/*      */   
/*      */   private String NESTED_DL_NAME(int index, int domainIdx) {
/*  359 */     return NESTED_DL_LOCAL(index) + "@" + DOMAIN_NAME(domainIdx);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private Set<String> NESTED_DL_NAMES(int index, int domainIdx, boolean afterRename)
/*      */   {
/*  366 */     int dIdx = afterRename ? DOMAIN_INDEX_AFTER_RENAME(domainIdx) : domainIdx;
/*  367 */     Set<String> names = new HashSet();
/*  368 */     String name = NESTED_DL_NAME(index, dIdx);
/*  369 */     names.add(name);
/*  370 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/*  371 */       String aliasName = NESTED_DL_ALIAS_NAME(index, d, afterRename ? DOMAIN_INDEX_AFTER_RENAME(d) : d);
/*  372 */       names.add(aliasName);
/*      */     }
/*  374 */     return names;
/*      */   }
/*      */   
/*      */   private String NESTED_DL_ALIAS_NAME(int targetIdx, int targetDomainIdx, int aliasDomainIdx) {
/*  378 */     return NAMEPREFIX_ALIAS + NESTED_DL_LOCAL(targetIdx) + "-" + LEAF_DOMAIN_NAME(targetDomainIdx) + "@" + DOMAIN_NAME(aliasDomainIdx);
/*      */   }
/*      */   
/*      */   private String SIGNATURE_NAME(Account acct, int index) {
/*  382 */     int idx = index + 1;
/*  383 */     return NAMEPREFIX_SIGNATURE + idx + "of-acct-" + acct.getName();
/*      */   }
/*      */   
/*      */   private String SIGNATURE_CONTENT(Account acct, int index) {
/*  387 */     int idx = index + 1;
/*  388 */     return "signature content of " + NAMEPREFIX_SIGNATURE + idx + "of-acct-" + acct.getName();
/*      */   }
/*      */   
/*      */   private String IDENTITY_NAME(Account acct, int index) {
/*  392 */     int idx = index + 1;
/*  393 */     return NAMEPREFIX_IDENTITY + idx + "of-acct-" + acct.getName();
/*      */   }
/*      */   
/*      */   private String DATASOURCE_NAME(Account acct, int index) {
/*  397 */     int idx = index + 1;
/*  398 */     return NAMEPREFIX_DATASOURCE + idx + "of-acct-" + acct.getName();
/*      */   }
/*      */   
/*      */   private void createDomain(String domainName) throws Exception {
/*  402 */     System.out.println("createDomain: " + domainName);
/*  403 */     Map<String, Object> attrs = new HashMap();
/*  404 */     Domain domain = prov.createDomain(domainName, attrs);
/*      */   }
/*      */   
/*      */   private String[] createSignatures(Account acct) throws Exception {
/*  408 */     String[] sigIds = new String[NUM_SIGNATURES];
/*      */     
/*  410 */     for (int i = 0; i < NUM_SIGNATURES; i++) {
/*  411 */       Map<String, Object> attrs = new HashMap();
/*  412 */       attrs.put("zimbraPrefMailSignature", SIGNATURE_CONTENT(acct, i));
/*  413 */       Signature entry = prov.createSignature(acct, SIGNATURE_NAME(acct, i), attrs);
/*  414 */       sigIds[i] = entry.getId();
/*      */     }
/*      */     
/*  417 */     return sigIds;
/*      */   }
/*      */   
/*      */   private void createIdentities(Account acct, String[] sigIds) throws Exception { Identity entry;
/*  421 */     for (int i = 0; i < NUM_IDENTITIES; i++) {
/*  422 */       Map<String, Object> attrs = new HashMap();
/*  423 */       attrs.put("zimbraPrefDefaultSignatureId", LdapUtil.generateUUID());
/*  424 */       attrs.put("zimbraPrefFromAddress", "micky.mouse@zimbra,com");
/*  425 */       attrs.put("zimbraPrefFromDisplay", "Micky Mouse");
/*  426 */       attrs.put("zimbraPrefReplyToEnabled", "TRUE");
/*  427 */       attrs.put("zimbraPrefReplyToAddress", "goofy@yahoo.com");
/*  428 */       attrs.put("zimbraPrefReplyToDisplay", "Micky");
/*  429 */       if (i < NUM_SIGNATURES)
/*  430 */         attrs.put("zimbraPrefDefaultSignatureId", sigIds[i]);
/*  431 */       entry = prov.createIdentity(acct, IDENTITY_NAME(acct, i), attrs);
/*      */     }
/*      */   }
/*      */   
/*      */   private void createDataSources(Account acct, String[] sigIds) throws Exception { DataSource entry;
/*  436 */     for (int i = 0; i < NUM_DATASOURCES; i++) {
/*  437 */       Map<String, Object> attrs = new HashMap();
/*  438 */       attrs.put("zimbraDataSourceEnabled", "TRUE");
/*  439 */       attrs.put("zimbraDataSourceConnectionType", "ssl");
/*  440 */       attrs.put("zimbraDataSourceFolderId", "inbox");
/*  441 */       attrs.put("zimbraDataSourceHost", "pop.google.com");
/*  442 */       attrs.put("zimbraDataSourceLeaveOnServer", "TRUE");
/*  443 */       attrs.put("zimbraDataSourcePassword", PASSWORD);
/*  444 */       attrs.put("zimbraDataSourcePort", "9999");
/*  445 */       attrs.put("zimbraDataSourceUsername", "mickymouse");
/*  446 */       attrs.put("zimbraDataSourceEmailAddress", "micky@google.com");
/*  447 */       attrs.put("zimbraPrefDefaultSignatureId", LdapUtil.generateUUID());
/*  448 */       attrs.put("zimbraPrefFromDisplay", "Micky Mouse");
/*  449 */       attrs.put("zimbraPrefReplyToAddress", "goofy@yahoo.com");
/*  450 */       attrs.put("zimbraPrefReplyToDisplay", "Micky");
/*  451 */       if (i < NUM_SIGNATURES)
/*  452 */         attrs.put("zimbraPrefDefaultSignatureId", sigIds[i]);
/*  453 */       entry = prov.createDataSource(acct, DataSourceType.pop3, DATASOURCE_NAME(acct, i), attrs);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private String makeAttrValue(String entryName, String attrName, Names.IDNName domainIDNName)
/*      */   {
/*  464 */     String domainName = domainIDNName.uName();
/*      */     
/*  466 */     if (("zimbraMailCatchAllAddress".equals(attrName)) || ("zimbraMailCatchAllCanonicalAddress".equals(attrName)) || ("zimbraMailCatchAllForwardingAddress".equals(attrName)))
/*      */     {
/*      */ 
/*  469 */       return "@" + domainName; }
/*  470 */     if ("zimbraPrefAllowAddressForDelegatedSender".equals(attrName)) {
/*  471 */       return entryName;
/*      */     }
/*  473 */     return attrName + "@" + domainName;
/*      */   }
/*      */   
/*      */   private Account createAccount(String acctName, Names.IDNName domainName) throws Exception
/*      */   {
/*  478 */     Map<String, Object> acctAttrs = new HashMap();
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  490 */     for (String attr : sAttrsToVerify) {
/*  491 */       acctAttrs.put(attr, makeAttrValue(acctName, attr, domainName));
/*      */     }
/*  493 */     Account acct = prov.createAccount(acctName, PASSWORD, acctAttrs);
/*  494 */     return acct;
/*      */   }
/*      */   
/*      */   private XMPPComponent createXMPPComponent(int xmppIndex, Domain domain) throws Exception
/*      */   {
/*  499 */     Server server = prov.getLocalServer();
/*      */     
/*  501 */     String routableName = XMPPCOMPONENT_NAME(xmppIndex, domain.getName());
/*      */     
/*  503 */     Map<String, Object> xmppAttrs = new HashMap();
/*  504 */     xmppAttrs.put("zimbraXMPPComponentClassName", "myclass");
/*  505 */     xmppAttrs.put("zimbraXMPPComponentCategory", "mycategory");
/*  506 */     xmppAttrs.put("zimbraXMPPComponentType", "mytype");
/*      */     
/*  508 */     XMPPComponent xmpp = prov.createXMPPComponent(routableName, domain, server, xmppAttrs);
/*  509 */     return xmpp;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void populateDomain(int domainIdx)
/*      */     throws Exception
/*      */   {
/*  517 */     Names.IDNName domainName = new Names.IDNName(DOMAIN_NAME(domainIdx));
/*  518 */     System.out.println("setupDomain: " + domainName.uName());
/*      */     
/*      */ 
/*  521 */     for (int a = 0; a < NUM_ACCOUNTS; a++) {
/*  522 */       Account acct = createAccount(ACCOUNT_NAME(a, domainIdx), domainName);
/*      */       
/*  524 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  525 */         prov.addAlias(acct, ACCOUNT_ALIAS_NAME(a, domainIdx, d));
/*      */       }
/*  527 */       String[] signatureIds = createSignatures(acct);
/*  528 */       createIdentities(acct, signatureIds);
/*  529 */       createDataSources(acct, signatureIds);
/*      */     }
/*      */     
/*      */ 
/*  533 */     for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
/*  534 */       Map<String, Object> dlAttrs = new HashMap();
/*  535 */       DistributionList dl = prov.createDistributionList(NESTED_DL_NAME(nd, domainIdx), dlAttrs);
/*      */       
/*  537 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  538 */         prov.addAlias(dl, NESTED_DL_ALIAS_NAME(nd, domainIdx, d));
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*  543 */     for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  544 */       Map<String, Object> dlAttrs = new HashMap();
/*  545 */       DistributionList dl = prov.createDistributionList(TOP_DL_NAME(td, domainIdx), dlAttrs);
/*      */       
/*  547 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  548 */         prov.addAlias(dl, TOP_DL_ALIAS_NAME(td, domainIdx, d));
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*  553 */     for (int dg = 0; dg < NUM_DYNAMIC_GROUPS; dg++) {
/*  554 */       Map<String, Object> dlAttrs = new HashMap();
/*  555 */       DynamicGroup dynGroup = prov.createDynamicGroup(DYNAMIC_GROUP_NAME(dg, domainIdx), dlAttrs);
/*      */       
/*  557 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  558 */         prov.addGroupAlias(dynGroup, DYNAMIC_GROUP_ALIAS_NAME(dg, domainIdx, d));
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void setupDLs(int domainIdx)
/*      */     throws Exception
/*      */   {
/*  568 */     String domainName = DOMAIN_NAME(domainIdx);
/*  569 */     System.out.println("crossLinkDomain: " + domainName);
/*      */     
/*      */ 
/*      */ 
/*  573 */     List<String>[][] nestedDLMembers = new ArrayList[NUM_DOMAINS][NUM_DLS_NESTED];
/*  574 */     List<String>[][] topDLMembers = new ArrayList[NUM_DOMAINS][NUM_DLS_TOP];
/*  575 */     List<String>[][] dynamicGroupMembers = new ArrayList[NUM_DOMAINS][NUM_DYNAMIC_GROUPS];
/*      */     
/*  577 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/*  578 */       for (int nd = 0; nd < NUM_DLS_TOP; nd++) {
/*  579 */         nestedDLMembers[d][nd] = new ArrayList();
/*      */       }
/*  581 */       for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  582 */         topDLMembers[d][td] = new ArrayList();
/*      */       }
/*  584 */       for (int dd = 0; dd < NUM_DYNAMIC_GROUPS; dd++) {
/*  585 */         dynamicGroupMembers[d][dd] = new ArrayList();
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  592 */     for (int a = 0; a < NUM_ACCOUNTS; a++) {
/*  593 */       Set<String> members = ACCOUNT_NAMES(a, domainIdx, false);
/*      */       
/*  595 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  596 */         for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
/*  597 */           for (String m : members)
/*  598 */             nestedDLMembers[d][nd].add(m);
/*      */         }
/*  600 */         for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  601 */           for (String m : members)
/*  602 */             topDLMembers[d][td].add(m);
/*      */         }
/*  604 */         for (int dd = 0; dd < NUM_DYNAMIC_GROUPS; dd++) {
/*  605 */           for (String m : members) {
/*  606 */             dynamicGroupMembers[d][dd].add(m);
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*  612 */     for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
/*  613 */       Set<String> members = NESTED_DL_NAMES(nd, domainIdx, false);
/*      */       
/*  615 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  616 */         for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  617 */           for (String m : members) {
/*  618 */             topDLMembers[d][td].add(m);
/*      */           }
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*  624 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/*  625 */       for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
/*  626 */         DistributionList dl = prov.get(Key.DistributionListBy.name, NESTED_DL_NAME(nd, d));
/*  627 */         prov.addMembers(dl, (String[])nestedDLMembers[d][nd].toArray(new String[0]));
/*      */       }
/*  629 */       for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  630 */         DistributionList dl = prov.get(Key.DistributionListBy.name, TOP_DL_NAME(td, d));
/*  631 */         prov.addMembers(dl, (String[])topDLMembers[d][td].toArray(new String[0]));
/*      */       }
/*  633 */       for (int dd = 0; dd < NUM_DYNAMIC_GROUPS; dd++) {
/*  634 */         Group dynGroup = prov.getGroup(Key.DistributionListBy.name, DYNAMIC_GROUP_NAME(dd, d));
/*  635 */         prov.addGroupMembers(dynGroup, (String[])dynamicGroupMembers[d][dd].toArray(new String[0]));
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void verifyOldDomain() throws Exception
/*      */   {
/*  642 */     String oldDomainName = DOMAIN_NAME(OLD_DOMAIN);
/*  643 */     Domain oldDomain = prov.get(Key.DomainBy.name, oldDomainName);
/*  644 */     Assert.assertTrue(oldDomain == null);
/*      */   }
/*      */   
/*      */   private void dumpAttrs(Map<String, Object> attrsIn, Set<String> specificAttrs)
/*      */   {
/*  649 */     System.out.println();
/*      */     
/*  651 */     TreeMap<String, Object> attrs = new TreeMap(attrsIn);
/*      */     
/*  653 */     for (Map.Entry<String, Object> entry : attrs.entrySet()) {
/*  654 */       String name = (String)entry.getKey();
/*  655 */       if ((specificAttrs == null) || (specificAttrs.contains(name.toLowerCase()))) {
/*  656 */         Object value = entry.getValue();
/*  657 */         if ((value instanceof String[])) {
/*  658 */           String[] sv = (String[])value;
/*  659 */           for (String aSv : sv) {
/*  660 */             System.out.println(name + ": " + aSv);
/*      */           }
/*  662 */         } else if ((value instanceof String)) {
/*  663 */           System.out.println(name + ": " + value);
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*  668 */     System.out.println();
/*      */   }
/*      */   
/*      */   private void dumpNames(String desc, List<NamedEntry> entries) {
/*  672 */     System.out.println();
/*      */     
/*  674 */     System.out.println("===== " + (desc == null ? "" : desc) + " =====");
/*  675 */     for (NamedEntry entry : entries) {
/*  676 */       System.out.println(entry.getName());
/*      */     }
/*  678 */     System.out.println();
/*      */   }
/*      */   
/*      */   private void dumpAttrs(Map<String, Object> attrsIn) {
/*  682 */     dumpAttrs(attrsIn, null);
/*      */   }
/*      */   
/*      */   private void dumpStrings(String notes, Collection<String> strings)
/*      */   {
/*  687 */     List<String> sorted = new ArrayList(strings);
/*  688 */     Collections.sort(sorted);
/*  689 */     System.out.println();
/*  690 */     System.out.println(notes);
/*      */     
/*  692 */     for (String s : sorted) {
/*  693 */       System.out.println(s);
/*      */     }
/*  695 */     System.out.println();
/*      */   }
/*      */   
/*      */   private static enum UnicodeOrACE {
/*  699 */     ACE, 
/*  700 */     UNICODE;
/*      */     
/*      */     private UnicodeOrACE() {} }
/*      */   
/*  704 */   Set<String> namedEntryListToNameSet(List<NamedEntry> entries, UnicodeOrACE unicodeOrACE) { Set<String> nameSet = new HashSet();
/*  705 */     for (NamedEntry entry : entries) { String name;
/*      */       String name;
/*  707 */       if ((entry instanceof MailTarget)) { String name;
/*  708 */         if (unicodeOrACE == UnicodeOrACE.UNICODE) {
/*  709 */           name = ((MailTarget)entry).getUnicodeName();
/*      */         } else {
/*  711 */           name = entry.getName();
/*      */         }
/*      */       } else {
/*  714 */         name = entry.getName();
/*      */       }
/*  716 */       nameSet.add(name);
/*      */     }
/*  718 */     return nameSet;
/*      */   }
/*      */   
/*      */   private NamedEntry getEntryByName(int objType, String name) throws Exception {
/*  722 */     switch (objType) {
/*      */     case 1: 
/*  724 */       return prov.get(Key.AccountBy.name, name);
/*      */     case 2: 
/*      */     case 4: 
/*      */     case 8: 
/*  728 */       return prov.getGroup(Key.DistributionListBy.name, name);
/*      */     }
/*  730 */     throw new Exception();
/*      */   }
/*      */   
/*      */   private void verifyDomainStatus(String domainName) throws Exception
/*      */   {
/*  735 */     Domain domain = prov.get(Key.DomainBy.name, domainName);
/*  736 */     Assert.assertTrue(domain != null);
/*      */     
/*  738 */     String domainStatus = domain.getAttr("zimbraDomainStatus");
/*  739 */     Assert.assertEquals("active", domainStatus);
/*  740 */     String mailStatus = domain.getAttr("zimbraMailStatus");
/*  741 */     Assert.assertEquals("enabled", mailStatus);
/*      */   }
/*      */   
/*      */   private Domain verifyNewDomainBasic(String domainId) throws Exception
/*      */   {
/*  746 */     Domain domainByName = prov.get(Key.DomainBy.name, DOMAIN_NAME(NEW_DOMAIN));
/*  747 */     Assert.assertTrue(domainByName != null);
/*      */     
/*      */ 
/*  750 */     Domain domainById = prov.get(Key.DomainBy.id, domainId);
/*  751 */     Assert.assertTrue(domainById != null);
/*      */     
/*  753 */     Verify.verifySameEntry(domainByName, domainById);
/*      */     
/*  755 */     verifyDomainStatus(DOMAIN_NAME(NEW_DOMAIN));
/*      */     
/*  757 */     return domainById;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void verifyNewDomainAttrs(Domain newDomain, Map<String, Object> oldDomainAttrs)
/*      */     throws Exception
/*      */   {
/*  765 */     Map<String, Object> newDomainAttrs = newDomain.getAttrs(false);
/*      */     
/*      */ 
/*  768 */     Map<String, Object> oldAttrs = new HashMap(oldDomainAttrs);
/*  769 */     Map<String, Object> newAttrs = new HashMap(newDomainAttrs);
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*  774 */     oldAttrs.remove("dc");
/*  775 */     oldAttrs.remove("o");
/*  776 */     oldAttrs.remove("zimbraDomainName");
/*  777 */     oldAttrs.remove("zimbraCreateTimestamp");
/*      */     
/*  779 */     newAttrs.remove("dc");
/*  780 */     newAttrs.remove("o");
/*  781 */     newAttrs.remove("zimbraDomainName");
/*  782 */     newAttrs.remove("zimbraCreateTimestamp");
/*      */     
/*  784 */     for (Map.Entry<String, Object> oldAttr : oldAttrs.entrySet()) {
/*  785 */       String oldKey = (String)oldAttr.getKey();
/*  786 */       Object oldValue = oldAttr.getValue();
/*      */       
/*  788 */       Object newValue = newAttrs.get(oldKey);
/*  789 */       if ((oldValue instanceof String[])) {
/*  790 */         Assert.assertTrue(newValue instanceof String[]);
/*  791 */         Set<String> oldV = new HashSet(Arrays.asList((String[])oldValue));
/*  792 */         Set<String> newV = new HashSet(Arrays.asList((String[])newValue));
/*  793 */         Verify.verifyEquals(oldV, newV);
/*      */       }
/*  795 */       else if ((oldValue instanceof String)) {
/*      */         try {
/*  797 */           Assert.assertEquals(oldValue, newValue);
/*      */         } catch (AssertionFailedError e) {
/*  799 */           System.out.println("Attribute  " + oldKey + " does not match!");
/*  800 */           throw e;
/*      */         }
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void verifyEntryAttrs(List<NamedEntry> list, Domain domain) throws Exception
/*      */   {
/*  808 */     Names.IDNName domainIDNName = new Names.IDNName(domain.getName());
/*      */     
/*  810 */     for (Iterator i$ = list.iterator(); i$.hasNext();) { e = (NamedEntry)i$.next();
/*  811 */       for (String attr : sAttrsToVerify) {
/*  812 */         String value = e.getAttr(attr);
/*      */         
/*  814 */         if ((e instanceof Account)) {
/*  815 */           Assert.assertEquals(makeAttrValue(((Account)e).getName(), attr, domainIDNName), value);
/*      */         }
/*      */       }
/*      */     }
/*      */     
/*      */     NamedEntry e;
/*      */   }
/*      */   
/*      */ 
/*      */   private void verifyEntries(int domainIdx, Domain domain)
/*      */     throws Exception
/*      */   {
/*  827 */     SearchDirectoryOptions options = new SearchDirectoryOptions();
/*  828 */     options.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.accounts, SearchDirectoryOptions.ObjectType.distributionlists, SearchDirectoryOptions.ObjectType.dynamicgroups });
/*      */     
/*      */ 
/*  831 */     options.setDomain(domain);
/*  832 */     options.setFilterString(ZLdapFilterFactory.FilterId.UNITTEST, null);
/*  833 */     List<NamedEntry> list = prov.searchDirectory(options);
/*      */     
/*      */ 
/*  836 */     Set<String> expectedEntries = new HashSet();
/*  837 */     for (int a = 0; a < NUM_ACCOUNTS; a++) {
/*  838 */       Names.IDNName name = new Names.IDNName(ACCOUNT_NAME(a, domainIdx));
/*  839 */       Account entry = prov.get(Key.AccountBy.name, name.uName());
/*  840 */       Assert.assertNotNull(entry);
/*  841 */       expectedEntries.add(name.uName());
/*      */     }
/*      */     
/*  844 */     for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
/*  845 */       Names.IDNName name = new Names.IDNName(NESTED_DL_NAME(nd, domainIdx));
/*  846 */       DistributionList entry = prov.get(Key.DistributionListBy.name, name.uName());
/*  847 */       Assert.assertNotNull(entry);
/*  848 */       expectedEntries.add(name.uName());
/*      */     }
/*      */     
/*  851 */     for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  852 */       Names.IDNName name = new Names.IDNName(TOP_DL_NAME(td, domainIdx));
/*  853 */       DistributionList entry = prov.get(Key.DistributionListBy.name, name.uName());
/*  854 */       Assert.assertNotNull(entry);
/*  855 */       expectedEntries.add(name.uName());
/*      */     }
/*      */     
/*  858 */     for (int td = 0; td < NUM_DYNAMIC_GROUPS; td++) {
/*  859 */       Names.IDNName name = new Names.IDNName(DYNAMIC_GROUP_NAME(td, domainIdx));
/*  860 */       DynamicGroup entry = (DynamicGroup)prov.getGroup(Key.DistributionListBy.name, name.uName());
/*  861 */       Assert.assertNotNull(entry);
/*  862 */       expectedEntries.add(name.uName());
/*      */     }
/*      */     
/*      */ 
/*  866 */     Set<String> actualEntries = namedEntryListToNameSet(list, UnicodeOrACE.UNICODE);
/*      */     
/*  868 */     dumpStrings("expectedEntries", expectedEntries);
/*  869 */     dumpStrings("actualEntries", actualEntries);
/*  870 */     Verify.verifyEquals(expectedEntries, actualEntries);
/*      */     
/*  872 */     verifyEntryAttrs(list, domain);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private void verifyDomainAliases(int domainIdx, Domain domain)
/*      */     throws Exception
/*      */   {
/*  881 */     SearchDirectoryOptions options = new SearchDirectoryOptions();
/*  882 */     options.setTypes(new SearchDirectoryOptions.ObjectType[] { SearchDirectoryOptions.ObjectType.aliases });
/*  883 */     options.setDomain(domain);
/*  884 */     options.setFilterString(ZLdapFilterFactory.FilterId.UNITTEST, null);
/*  885 */     List<NamedEntry> list = prov.searchDirectory(options);
/*      */     
/*      */ 
/*  888 */     Set<String> expectedAliases = new HashSet();
/*  889 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/*  890 */       for (int a = 0; a < NUM_ACCOUNTS; a++) {
/*  891 */         expectedAliases.add(new Names.IDNName(ACCOUNT_ALIAS_NAME(a, d, domainIdx)).uName());
/*      */       }
/*  893 */       for (int nd = 0; nd < NUM_DLS_NESTED; nd++) {
/*  894 */         expectedAliases.add(new Names.IDNName(NESTED_DL_ALIAS_NAME(nd, d, domainIdx)).uName());
/*      */       }
/*  896 */       for (int td = 0; td < NUM_DLS_TOP; td++) {
/*  897 */         expectedAliases.add(new Names.IDNName(TOP_DL_ALIAS_NAME(td, d, domainIdx)).uName());
/*      */       }
/*  899 */       for (int dg = 0; dg < NUM_DYNAMIC_GROUPS; dg++) {
/*  900 */         expectedAliases.add(new Names.IDNName(DYNAMIC_GROUP_ALIAS_NAME(dg, d, domainIdx)).uName());
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*  905 */     Set<String> actualAliases = namedEntryListToNameSet(list, UnicodeOrACE.UNICODE);
/*      */     
/*      */ 
/*  908 */     Verify.verifyEquals(expectedAliases, actualAliases);
/*      */     
/*      */ 
/*  911 */     for (NamedEntry entry : list) {
/*  912 */       Assert.assertTrue(entry instanceof Alias);
/*      */       
/*  914 */       NamedEntry target = prov.searchAliasTarget((Alias)entry, true);
/*  915 */       Assert.assertNotNull(target);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private void verifyAliasesOfEntriesInDomain(int objType, Domain domain)
/*      */     throws Exception
/*      */   {
/*  926 */     for (int i = 0; i < NUM_OBJS(objType); i++)
/*      */     {
/*  928 */       String entryName = OBJ_NAME(objType, i, NEW_DOMAIN);
/*  929 */       NamedEntry entry = getEntryByName(objType, entryName);
/*  930 */       Assert.assertNotNull(entry);
/*      */       
/*      */ 
/*  933 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  934 */         int aliasDomainIdx = DOMAIN_INDEX_AFTER_RENAME(d);
/*  935 */         String aliasName = GET_ALIAS_NAME(objType, i, OLD_DOMAIN, aliasDomainIdx);
/*  936 */         NamedEntry entryByAlias = getEntryByName(objType, aliasName);
/*  937 */         Assert.assertNotNull(entryByAlias);
/*  938 */         Verify.verifySameEntry(entry, entryByAlias);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   private void verifyAliases(int domainIdx, Domain domain) throws Exception {
/*  944 */     verifyDomainAliases(domainIdx, domain);
/*      */     
/*  946 */     verifyAliasesOfEntriesInDomain(1, domain);
/*  947 */     verifyAliasesOfEntriesInDomain(2, domain);
/*  948 */     verifyAliasesOfEntriesInDomain(4, domain);
/*  949 */     verifyAliasesOfEntriesInDomain(8, domain);
/*      */   }
/*      */   
/*      */   private void verifyMemberOf(int memberType, int dlTypes, int domainIdx) throws Exception {
/*  953 */     for (int i = 0; i < NUM_OBJS(memberType); i++) {
/*  954 */       String name = OBJ_NAME(memberType, i, domainIdx);
/*  955 */       NamedEntry entry = getEntryByName(memberType, name);
/*  956 */       Assert.assertNotNull(entry);
/*      */       
/*  958 */       Set<String> expectedNames = new HashSet();
/*      */       
/*  960 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/*  961 */         int dIdx = DOMAIN_INDEX_AFTER_RENAME(d);
/*  962 */         if ((dlTypes & 0x2) != 0) {
/*  963 */           for (int dlIdx = 0; dlIdx < NUM_DLS_NESTED; dlIdx++) {
/*  964 */             expectedNames.add(new Names.IDNName(NESTED_DL_NAME(dlIdx, dIdx)).aName());
/*      */           }
/*      */         }
/*  967 */         if ((dlTypes & 0x4) != 0) {
/*  968 */           for (int dlIdx = 0; dlIdx < NUM_DLS_TOP; dlIdx++) {
/*  969 */             expectedNames.add(new Names.IDNName(TOP_DL_NAME(dlIdx, dIdx)).aName());
/*      */           }
/*      */         }
/*      */       }
/*      */       
/*      */ 
/*  975 */       HashMap<String, String> via = new HashMap();
/*      */       List lists;
/*  977 */       List lists; if (memberType == 1) {
/*  978 */         lists = prov.getDistributionLists((Account)entry, false, via);
/*      */       } else {
/*  980 */         lists = prov.getDistributionLists((DistributionList)entry, false, via);
/*      */       }
/*      */       
/*  983 */       Set<String> actualNames = namedEntryListToNameSet(lists, UnicodeOrACE.ACE);
/*      */       
/*      */ 
/*  986 */       Verify.verifyEquals(expectedNames, actualNames);
/*      */     }
/*      */   }
/*      */   
/*      */   private void verifyHasMembers(int dlType, int memberTypes, int domainIdx) throws Exception
/*      */   {
/*  992 */     for (int dlIdx = 0; dlIdx < NUM_OBJS(dlType); dlIdx++) {
/*  993 */       String name = OBJ_NAME(dlType, dlIdx, domainIdx);
/*  994 */       DistributionList dl = prov.get(Key.DistributionListBy.name, name);
/*  995 */       Assert.assertNotNull(dl);
/*      */       
/*  997 */       Set<String> expectedNames = new HashSet();
/*      */       
/*  999 */       for (int d = 0; d < NUM_DOMAINS; d++) {
/* 1000 */         int dIdx = DOMAIN_INDEX_AFTER_RENAME(d);
/*      */         
/* 1002 */         if ((memberTypes & 0x1) != 0) {
/* 1003 */           for (int i = 0; i < NUM_ACCOUNTS; i++) {
/* 1004 */             Set<String> names = ACCOUNT_NAMES(i, dIdx, true);
/* 1005 */             for (String n : names) {
/* 1006 */               expectedNames.add(new Names.IDNName(n).uName());
/*      */             }
/*      */           }
/*      */         }
/*      */         
/* 1011 */         if ((memberTypes & 0x2) != 0) {
/* 1012 */           for (int i = 0; i < NUM_DLS_NESTED; i++) {
/* 1013 */             Set<String> names = NESTED_DL_NAMES(i, dIdx, true);
/* 1014 */             for (String n : names) {
/* 1015 */               expectedNames.add(new Names.IDNName(n).uName());
/*      */             }
/*      */           }
/*      */         }
/*      */         
/* 1020 */         if ((memberTypes & 0x4) != 0) {
/* 1021 */           for (int i = 0; i < NUM_DLS_TOP; i++) {
/* 1022 */             Set<String> names = TOP_DL_NAMES(i, dIdx, true);
/* 1023 */             for (String n : names) {
/* 1024 */               expectedNames.add(new Names.IDNName(n).uName());
/*      */             }
/*      */           }
/*      */         }
/*      */       }
/*      */       
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1036 */       String[] members = dl.getAllMembers();
/* 1037 */       Set<String> actualNames = new HashSet(Arrays.asList(members));
/*      */       
/* 1039 */       if ((prov instanceof LdapProvisioning)) {
/* 1040 */         Set<String> actualNamesUnicode = Sets.newHashSet();
/* 1041 */         for (String addr : actualNames) {
/* 1042 */           String addrUnicode = IDNUtil.toUnicode(addr);
/* 1043 */           actualNamesUnicode.add(addrUnicode);
/*      */         }
/* 1045 */         actualNames = actualNamesUnicode;
/*      */       }
/*      */       
/*      */ 
/* 1049 */       Verify.verifyEquals(expectedNames, actualNames);
/*      */     }
/*      */   }
/*      */   
/*      */   private void verifyDLMembership(int domainIdx, Domain domain)
/*      */     throws Exception
/*      */   {
/* 1056 */     verifyMemberOf(1, 6, domainIdx);
/*      */     
/*      */ 
/* 1059 */     verifyMemberOf(2, 4, domainIdx);
/* 1060 */     verifyHasMembers(2, 1, domainIdx);
/*      */     
/*      */ 
/* 1063 */     verifyHasMembers(4, 3, domainIdx);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   private void verifyDomain(int domainIdx)
/*      */     throws Exception
/*      */   {
/* 1071 */     System.out.println("Verifying domain " + DOMAIN_NAME(domainIdx));
/*      */     
/* 1073 */     String domainName = DOMAIN_NAME(domainIdx);
/* 1074 */     Domain domain = prov.get(Key.DomainBy.name, domainName);
/*      */     
/* 1076 */     verifyEntries(domainIdx, domain);
/* 1077 */     verifyAliases(domainIdx, domain);
/* 1078 */     verifyDLMembership(domainIdx, domain);
/*      */   }
/*      */   
/*      */   private void verifyNewDomain(String domainId, Map<String, Object> oldDomainAttrs) throws Exception {
/* 1082 */     Domain newDomain = verifyNewDomainBasic(domainId);
/* 1083 */     verifyNewDomainAttrs(newDomain, oldDomainAttrs);
/* 1084 */     verifyDomain(NEW_DOMAIN);
/*      */   }
/*      */   
/*      */   private void verifyOtherDomains() throws Exception {
/* 1088 */     for (int d = 0; d < NUM_DOMAINS; d++) {
/* 1089 */       if (d != OLD_DOMAIN)
/* 1090 */         verifyDomain(d);
/*      */     }
/*      */   }
/*      */   
/*      */   private void verifyXMPPComponent(int index, Domain newDomain) throws Exception {
/* 1095 */     String newRoutableName = XMPPCOMPONENT_NAME(index, newDomain.getName());
/*      */     
/* 1097 */     XMPPComponent xmpp = prov.get(Key.XMPPComponentBy.name, newRoutableName);
/* 1098 */     Assert.assertNotNull(xmpp);
/*      */     
/* 1100 */     String domainId = newDomain.getId();
/* 1101 */     String xmppDomainId = xmpp.getAttr("zimbraDomainId");
/* 1102 */     Assert.assertEquals(domainId, xmppDomainId);
/*      */   }
/*      */   
/*      */   private void verifyXMPPComponents() throws Exception
/*      */   {
/* 1107 */     Domain newDomain = prov.get(Key.DomainBy.name, DOMAIN_NAME(NEW_DOMAIN));
/*      */     
/* 1109 */     for (int i = 0; i < NUM_XMPPCOMPONENTS; i++) {
/* 1110 */       verifyXMPPComponent(i, newDomain);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   private void renameDomainTest()
/*      */     throws Exception
/*      */   {
/* 1120 */     prepareDomain();
/* 1121 */     Domain oldDomain = prov.get(Key.DomainBy.name, DOMAIN_NAME(OLD_DOMAIN));
/* 1122 */     String oldDomainId = oldDomain.getId();
/* 1123 */     Map<String, Object> oldDomainAttrs = oldDomain.getAttrs(false);
/*      */     
/* 1125 */     System.out.println("rd " + oldDomain.getId() + " " + DOMAIN_NAME(NEW_DOMAIN));
/*      */     
/*      */ 
/* 1128 */     ((LdapProv)prov).renameDomain(oldDomain.getId(), DOMAIN_NAME(NEW_DOMAIN));
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1137 */     ((LdapProv)prov).flushCache(CacheEntryType.domain, null);
/* 1138 */     ((LdapProv)prov).flushCache(CacheEntryType.account, null);
/* 1139 */     ((LdapProv)prov).flushCache(CacheEntryType.group, null);
/*      */     
/* 1141 */     verifyOldDomain();
/* 1142 */     verifyNewDomain(oldDomainId, oldDomainAttrs);
/* 1143 */     verifyOtherDomains();
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1157 */     setLdapProv();
/* 1158 */     verifyXMPPComponents();
/*      */   }
/*      */   
/*      */   private void renameToExistingDomainTest() throws Exception
/*      */   {
/* 1163 */     setLdapProv();
/* 1164 */     String srcDomainName = DOMAIN_NAME("src");
/* 1165 */     String tgtDomainName = DOMAIN_NAME("target");
/* 1166 */     Domain srcDomain = prov.createDomain(srcDomainName, new HashMap());
/* 1167 */     Assert.assertNotNull(srcDomain);
/* 1168 */     Domain tgtDomain = prov.createDomain(tgtDomainName, new HashMap());
/* 1169 */     Assert.assertNotNull(tgtDomain);
/*      */     
/* 1171 */     boolean ok = false;
/*      */     try {
/* 1173 */       ((LdapProv)prov).renameDomain(srcDomain.getId(), tgtDomainName);
/*      */     } catch (ServiceException e) {
/* 1175 */       Assert.assertEquals("service.INVALID_REQUEST", e.getCode());
/* 1176 */       Assert.assertEquals("invalid request: domain " + new Names.IDNName(tgtDomainName).aName() + " already exists", e.getMessage());
/*      */     }
/*      */     
/* 1179 */     verifyDomainStatus(srcDomainName);
/* 1180 */     verifyDomainStatus(tgtDomainName);
/*      */   }
/*      */   
/*      */   @Test
/*      */   public void testRenameDomain() throws Exception {
/*      */     try {
/* 1186 */       System.out.println("\nTest " + TEST_ID + " starting\n");
/*      */       
/* 1188 */       renameDomainTest();
/* 1189 */       renameToExistingDomainTest();
/*      */       
/* 1191 */       System.out.println("\nTest " + TEST_ID + " done!");
/*      */     } catch (ServiceException e) {
/* 1193 */       Throwable cause = e.getCause();
/* 1194 */       System.out.println("ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? "" : new StringBuilder().append(" (cause: ").append(cause.getClass().getName()).append(" ").append(cause.getMessage()).append(")").toString()));
/*      */       
/* 1196 */       e.printStackTrace(System.out);
/* 1197 */       System.out.println("\nTest " + TEST_ID + " failed!");
/*      */     } catch (AssertionFailedError e) {
/* 1199 */       System.out.println("\n===== assertion failed =====");
/* 1200 */       System.out.println(e.getMessage());
/* 1201 */       e.printStackTrace(System.out);
/*      */     }
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvRenameDomain.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */